<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qquickdraghandler.cpp -->
  <title>DragHandler QML 类型 | Qt Quick 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtquick-index.html">Qt Quick 模块</a></td><td ><a href="qtquick-qmlmodule.html">QML类型</a></td><td >DragHandler QML 类型</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtquick-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">目录</a></h3>
<ul>
<li class="level1"><a href="#properties">属性</a></li>
<li class="level1"><a href="#details">详细信息</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">DragHandler QML 类型</h1>
<span class="subtitle"></span>
<!-- $$$DragHandler-brief -->
<p>Handler for dragging. <a href="#details">更多...</a></p>
<!-- @@@DragHandler -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> 导入语句：</td><td class="memItemRight bottomAlign"> import QtQuick 2.12</td></tr><tr><td class="memItemLeft rightAlign topAlign">继承自：</td><td class="memItemRight bottomAlign"> <p><a href="qml-qtquick-multipointhandler.html">MultiPointHandler</a></p>
</td></tr></table></div><ul>
<li><a href="qml-qtquick-draghandler-members.html">所有成员的列表，包括继承成员</a></li>
</ul>
<a name="properties"></a>
<h2 id="properties">属性</h2>
<ul>
<li class="fn"><b><b><a href="qml-qtquick-draghandler.html#translation-prop">translation</a></b></b> : QVector2D</li>
<li class="fn"><b><b><a href="qml-qtquick-draghandler.html#xAxis-prop">xAxis</a></b></b><ul>
<li class="fn"><b><b><a href="qml-qtquick-draghandler.html#xAxis.minimum-prop">xAxis.minimum</a></b></b> : real</li>
<li class="fn"><b><b><a href="qml-qtquick-draghandler.html#xAxis.maximum-prop">xAxis.maximum</a></b></b> : real</li>
<li class="fn"><b><b><a href="qml-qtquick-draghandler.html#xAxis.enabled-prop">xAxis.enabled</a></b></b> : bool</li>
</ul>
</li>
<li class="fn"><b><b><a href="qml-qtquick-draghandler.html#yAxis-prop">yAxis</a></b></b><ul>
<li class="fn"><b><b><a href="qml-qtquick-draghandler.html#yAxis.minimum-prop">yAxis.minimum</a></b></b> : real</li>
<li class="fn"><b><b><a href="qml-qtquick-draghandler.html#yAxis.maximum-prop">yAxis.maximum</a></b></b> : real</li>
<li class="fn"><b><b><a href="qml-qtquick-draghandler.html#yAxis.enabled-prop">yAxis.enabled</a></b></b> : bool</li>
</ul>
</li>
</ul>
<!-- $$$DragHandler-description -->
<a name="details"></a>
<h2 id="details">详细信息</h2>
<p><a href="qml-qtquick-draghandler.html">DragHandler</a> is a handler that is used to interactively move an Item. Like other Input Handlers, by default it is fully functional, and manipulates its <a href="qml-qtquick-draghandler.html#target-prop">target</a>.</p>
<pre class="qml">

  import QtQuick 2.12

  <span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> {
      <span class="name">width</span>: <span class="number">100</span>
      <span class="name">height</span>: <span class="number">100</span>
      <span class="name">color</span>: <span class="string">&quot;lightsteelblue&quot;</span>
      <span class="type"><a href="qml-qtquick-draghandler.html">DragHandler</a></span> { }
  }

</pre>
<p>It has properties to restrict the range of dragging.</p>
<p>If it is declared within one Item but is assigned a different <a href="qml-qtquick-draghandler.html#target-prop">target</a>, then it handles events within the bounds of the <a href="qml-qtquick-draghandler.html#parent-prop">parent</a> Item but manipulates the <code>target</code> Item instead:</p>
<pre class="qml">

  import QtQuick 2.12

  <span class="type"><a href="qml-qtquick-item.html">Item</a></span> {
      <span class="name">width</span>: <span class="number">640</span>
      <span class="name">height</span>: <span class="number">480</span>

      <span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> {
          <span class="name">id</span>: <span class="name">feedback</span>
          <span class="name">border</span>.color: <span class="string">&quot;red&quot;</span>
          <span class="name">width</span>: <span class="name">Math</span>.<span class="name">max</span>(<span class="number">10</span>, <span class="name">handler</span>.<span class="name">centroid</span>.<span class="name">ellipseDiameters</span>.<span class="name">width</span>)
          <span class="name">height</span>: <span class="name">Math</span>.<span class="name">max</span>(<span class="number">10</span>, <span class="name">handler</span>.<span class="name">centroid</span>.<span class="name">ellipseDiameters</span>.<span class="name">height</span>)
          <span class="name">radius</span>: <span class="name">Math</span>.<span class="name">max</span>(<span class="name">width</span>, <span class="name">height</span>) <span class="operator">/</span> <span class="number">2</span>
          <span class="name">visible</span>: <span class="name">handler</span>.<span class="name">active</span>
      }

      <span class="type"><a href="qml-qtquick-draghandler.html">DragHandler</a></span> {
          <span class="name">id</span>: <span class="name">handler</span>
          <span class="name">target</span>: <span class="name">feedback</span>
      }
  }

</pre>
<p>A third way to use it is to set <a href="qml-qtquick-draghandler.html#target-prop">target</a> to <code>null</code> and react to property changes in some other way:</p>
<pre class="qml">

  import QtQuick 2.12

  <span class="type"><a href="qml-qtquick-item.html">Item</a></span> {
      <span class="name">width</span>: <span class="number">640</span>
      <span class="name">height</span>: <span class="number">480</span>

      <span class="type"><a href="qml-qtquick-draghandler.html">DragHandler</a></span> {
          <span class="name">id</span>: <span class="name">handler</span>
          <span class="name">target</span>: <span class="number">null</span>
      }

      <span class="type"><a href="qml-qtquick-text.html">Text</a></span> {
          <span class="name">color</span>: <span class="name">handler</span>.<span class="name">active</span> ? <span class="string">&quot;darkgreen&quot;</span> : <span class="string">&quot;black&quot;</span>
          <span class="name">text</span>: <span class="name">handler</span>.<span class="name">centroid</span>.<span class="name">centroid</span>.<span class="name">x</span>.<span class="name">toFixed</span>(<span class="number">1</span>) <span class="operator">+</span> <span class="string">&quot;,&quot;</span> <span class="operator">+</span> <span class="name">handler</span>.<span class="name">centroid</span>.<span class="name">position</span>.<span class="name">y</span>.<span class="name">toFixed</span>(<span class="number">1</span>)
          <span class="name">x</span>: <span class="name">handler</span>.<span class="name">centroid</span>.<span class="name">position</span>.<span class="name">x</span> <span class="operator">-</span> <span class="name">width</span> <span class="operator">/</span> <span class="number">2</span>
          <span class="name">y</span>: <span class="name">handler</span>.<span class="name">centroid</span>.<span class="name">position</span>.<span class="name">y</span> <span class="operator">-</span> <span class="name">height</span>
      }
  }

</pre>
<p>If minimumPointCount and maximumPointCount are set to values larger than 1, the user will need to drag that many fingers in the same direction to start dragging. A multi-finger drag gesture can be detected independently of both a (default) single-finger <a href="qml-qtquick-draghandler.html">DragHandler</a> and a <a href="qml-qtquick-pinchhandler.html">PinchHandler</a> on the same Item, and thus can be used to adjust some other feature independently of the usual pinch behavior: for example adjust a tilt transformation, or adjust some other numeric value, if the <code>target</code> is set to null. But if the <code>target</code> is an Item, <code>centroid</code> is the point at which the drag begins and to which the <code>target</code> will be moved (subject to constraints).</p>
<p>At this time, drag-and-drop is not yet supported.</p>
<p><b>请参考 </b><a href="qml-qtquick-drag.html">Drag</a> 和 <a href="qml-qtquick-mousearea.html">MouseArea</a>。</p>
<!-- @@@DragHandler -->
<h2>属性文档</h2>
<!-- $$$translation -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="translation-prop">
<td class="tblQmlPropNode"><p>
<a name="translation-prop"></a><span class="qmlreadonly">[read-only] </span><span class="name">translation</span> : <span class="type">QVector2D</span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>The translation since the gesture began.</p>
</div></div><!-- @@@translation -->
<br/>
<!-- $$$xAxis -->
<div class="qmlitem"><div class="qmlproto"><div class="table"><table class="qmlname"><tr valign="top" class="even" id="xAxis-prop"><th class="centerAlign"><p><a name="xAxis-prop"></a><b>xAxis group</b></p></th></tr><tr valign="top" class="odd" id="xAxis.minimum-prop"><td class="tblQmlPropNode"><p><a name="xAxis.minimum-prop"></a><span class="name">xAxis.minimum</span> : <span class="type"><a href="../qtqml/qml-real.html">real</a></span></p></td></tr><tr valign="top" class="odd" id="xAxis.maximum-prop"><td class="tblQmlPropNode"><p><a name="xAxis.maximum-prop"></a><span class="name">xAxis.maximum</span> : <span class="type"><a href="../qtqml/qml-real.html">real</a></span></p></td></tr><tr valign="top" class="odd" id="xAxis.enabled-prop"><td class="tblQmlPropNode"><p><a name="xAxis.enabled-prop"></a><span class="name">xAxis.enabled</span> : <span class="type"><a href="../qtqml/qml-bool.html">bool</a></span></p></td></tr></table></div></div><div class="qmldoc"><p><code>xAxis</code> controls the constraints for horizontal dragging.</p>
<p><code>minimum</code> is the minimum acceptable value of <a href="qml-qtquick-item.html#x-prop">x</a> to be applied to the <a href="qml-qtquick-draghandler.html#target-prop">target</a>. <code>maximum</code> is the maximum acceptable value of <a href="qml-qtquick-item.html#x-prop">x</a> to be applied to the <a href="qml-qtquick-draghandler.html#target-prop">target</a>. If <code>enabled</code> is true, horizontal dragging is allowed.</p>
</div></div><!-- @@@xAxis -->
<br/>
<!-- $$$yAxis -->
<div class="qmlitem"><div class="qmlproto"><div class="table"><table class="qmlname"><tr valign="top" class="even" id="yAxis-prop"><th class="centerAlign"><p><a name="yAxis-prop"></a><b>yAxis group</b></p></th></tr><tr valign="top" class="odd" id="yAxis.minimum-prop"><td class="tblQmlPropNode"><p><a name="yAxis.minimum-prop"></a><span class="name">yAxis.minimum</span> : <span class="type"><a href="../qtqml/qml-real.html">real</a></span></p></td></tr><tr valign="top" class="odd" id="yAxis.maximum-prop"><td class="tblQmlPropNode"><p><a name="yAxis.maximum-prop"></a><span class="name">yAxis.maximum</span> : <span class="type"><a href="../qtqml/qml-real.html">real</a></span></p></td></tr><tr valign="top" class="odd" id="yAxis.enabled-prop"><td class="tblQmlPropNode"><p><a name="yAxis.enabled-prop"></a><span class="name">yAxis.enabled</span> : <span class="type"><a href="../qtqml/qml-bool.html">bool</a></span></p></td></tr></table></div></div><div class="qmldoc"><p><code>yAxis</code> controls the constraints for vertical dragging.</p>
<p><code>minimum</code> is the minimum acceptable value of <a href="qml-qtquick-item.html#y-prop">y</a> to be applied to the <a href="qml-qtquick-draghandler.html#target-prop">target</a>. <code>maximum</code> is the maximum acceptable value of <a href="qml-qtquick-item.html#y-prop">y</a> to be applied to the <a href="qml-qtquick-draghandler.html#target-prop">target</a>. If <code>enabled</code> is true, vertical dragging is allowed.</p>
</div></div><!-- @@@yAxis -->
<br/>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
